package com.novax.ex.activity.provider.handler.provider;

import com.novax.ex.common.constant.MqConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

/**
 * @Description 商品消息生产者
 * @Author zhaolei
 * @Date 2/21/23 4:22 PM
 * @Version 1.0
 */
@Slf4j
@Component
public class MallProductProvider {
    @Resource
    private AmqpTemplate amqpTemplate;

    /**
     * @description: 商品上架
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallProduct]
     * @return: void
     **/
    public boolean sendPutOn(String mallProduct) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallProduct.Put_On_Queue, mallProduct);
            log.info("商品消息跟踪sendPutOn："+mallProduct);
            flag = true;
        } catch (Exception e) {
            log.error("[商品上架消息异常] msg = {}", mallProduct, e);
        }
        return flag;
    }

    /**
     * @description: 商品删除
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallProduct]
     * @return: void
     **/
    public boolean sendDel(String mallProduct) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallProduct.Del_Queue, mallProduct);
            log.info("商品消息跟踪sendDel："+mallProduct);
            flag = true;
        } catch (Exception e) {
            log.error("[商品删除消息异常] msg = {}", mallProduct, e);
        }
        return flag;
    }

    /**
     * @description: 商品售价修改
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallProduct]
     * @return: void
     **/
    public boolean sendUpdatePrice(String mallProduct) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallProduct.Update_Price_Queue, mallProduct);
            log.info("商品售价修改消息跟踪sendUpdatePrice："+mallProduct);
            flag = true;
        } catch (Exception e) {
            log.error("[商品售价修改异常] msg = {}", mallProduct, e);
        }
        return flag;
    }

    /**
     * @description: 商品成本修改
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallProduct]
     * @return: void
     **/
    public boolean sendUpdateCost(String mallProduct) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallProduct.Update_Cost_Queue, mallProduct);
            log.info("商品成本修改消息跟踪sendUpdateCost："+mallProduct);
            flag = true;
        } catch (Exception e) {
            log.error("[商品成本修改异常] msg = {}", mallProduct, e);
        }
        return flag;
    }
}
